package utils

import (
	"fmt"

	"github.com/xuri/excelize/v2"
)

func ReadExcel(filePath string, sheetName string) ([]map[string]string, error) {
	f, err := excelize.OpenFile(filePath)
	if err != nil {
		return nil, err
	}
	defer func() {
		// Close the spreadsheet.
		if err := f.Close(); err != nil {
			fmt.Println(err)
		}
	}()

	// Get all the rows in the Sheet1.
	rows, err := f.GetRows(sheetName)
	if err != nil {
		return nil, fmt.Errorf("GetRows from sheet:%s error: %v", sheetName, err)
	}
	for _, row := range rows {
		for _, colCell := range row {
			fmt.Print(colCell, "\t")
		}
		fmt.Println()
	}

	return nil, nil
}
